#
# Copyright 2009, Josef Kyrian <josef.kyrian@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

from PyQt4 import QtGui, QtCore, Qt


class Config:
	# allow standart input
	allowStandartInput = None
	
	# font of items
	itemFont = None
	
	# background of whole menu
	bgColor = None
	
	# background outline color
	bgOutlineColor = None
	
	# color or items
	itemColor = None
	
	# color or items outline
	itemOutlineColor = None
	
	# background color or items
	itemBgColor = None
	
	# color or items background outline
	selectedItemBgOutlineColor = None
	
	# background color or items
	selectedItemBgColor = None
	
	# log filename
	logFilename = None
	
	# lircrc filename
	lircrcFilename = None
	
	# funOneProgramName
	funOneProgramName = None
	
	#funOneRunCommand
	funOneRunCommand = None
	
	# funOneStopCommand
	funOneStopCommand = None
	
	# funOneRestartCommand
	funOneRestartCommand = None
	
	# mythTvProgramName
	mythTvProgramName = None
	
	# mythTvRunCommand
	mythTvRunCommand = None
	
	# mythTvRestartCommand
	mythTvRestartCommand = None
	
	# mythTvBackendRestartCommand
	mythTvBackendRestartCommand = None
	
	# screenSaverRunCommand
	screenSaverRunCommand = None
	
	# shutdown command
	shutdownCommand = None

	# reboot command
	rebootCommand = None
	
	# volumeIncreaseCommand
	volumeIncreaseCommand = None
	
	# volumeDecreaseCommand
	volumeDecreaseCommand = None
	
	# irEventSoundFilename
	irEventSoundFilename = None


	def __init__(self):
		"""
		Init
		"""
		pass
	#enddef
	
	
	def _getQColor(self, v):
		"""
		Returns QColor instance
		"""
		r, g, b = v.split(',')
		return QtGui.QColor(int(r.strip()), int(g.strip()), int(b.strip()))
	#enddef
	
	
	def load(self, filename):
		"""
		Load
		"""
		conf = {}
		f = open(filename, 'r')
		lines = f.readlines()
		for line in lines:
			if (len(line) > 0 and line[0] != '#' and line[0] != '['):
				equal_pos = line.find('=')
				if (equal_pos != -1):
					conf[line[:equal_pos].strip()] = line[equal_pos + 1 :].strip()
				#endif
			#endif
		#endfor
		f.close()
		
		self.allowStandartInput = bool(int(conf['allowStandartInput']))
		
		self.bgColor = self._getQColor(conf['bgColor'])
		self.bgOutlineColor = self._getQColor(conf['bgOutlineColor'])
		self.itemColor = self._getQColor(conf['itemColor'])
		self.itemOutlineColor = self._getQColor(conf['itemOutlineColor'])
		self.selectedItemBgColor = self._getQColor(conf['selectedItemBgColor'])
		self.selectedItemBgOutlineColor = self._getQColor(conf['selectedItemBgOutlineColor'])
		
		self.itemFont = QtGui.QFont(conf['itemFontFamily'], int(conf['itemFontSize']))
		
		self.logFilename = conf['logFilename']
		
		self.lircrcFilename = conf['lircrcFilename']
		
		self.funOneProgramName = conf['funOneProgramName']
		self.funOneRunCommand = conf['funOneRunCommand']
		self.funOneStopCommand = conf['funOneStopCommand']
		self.funOneRestartCommand = conf['funOneRestartCommand']
		
		self.mythTvProgramName = conf['mythTvProgramName']
		self.mythTvRunCommand = conf['mythTvRunCommand']
		self.mythTvRestartCommand = conf['mythTvRestartCommand']
		self.mythTvBackendRestartCommand = conf['mythTvBackendRestartCommand']
		
		self.screenSaverRunCommand = conf['screenSaverRunCommand']
		
		self.shutdownCommand = conf['shutdownCommand']
		self.rebootCommand = conf['rebootCommand']
		
		self.volumeIncreaseCommand = conf['volumeIncreaseCommand']
		self.volumeDecreaseCommand = conf['volumeDecreaseCommand']
		
		self.irEventSoundFilename = conf['irEventSoundFilename']
	#enddef
#endclass


config = Config()
